package cn.cocho.custom.yunCashierDf.log.controller;

import cn.cocho.common.web.jqgrid.JQGridContants;
import cn.cocho.common.web.jqgrid.JQGridPage;
import cn.cocho.common.web.jqgrid.JQGridUtils;
import cn.cocho.custom.yunCashierDf.log.domain.LoginLogInfo;
import cn.cocho.custom.yunCashierDf.log.service.LoginLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by WQJ on 2016-06-28.
 */
@Controller
public class LoginLogInfoController {

    @Autowired
    private LoginLoginInfoService loginLoginInfoService;


    @ResponseBody
    @RequestMapping(value = "/members/log/getLoginLogInfoList")
    public JQGridPage getLoginLogInfoList(JQGridPage<LoginLogInfo> pageJQGrid) {
        return loginLoginInfoService.getListByJQgrid(pageJQGrid);
    }

    @ResponseBody
    @RequestMapping(value = "/members/log/editLoginLogInfo")
    public void editLoginLogInfo(LoginLogInfo loginLogInfo, HttpServletResponse response) {
        String warnMessage = null;
        if (loginLogInfo.getOper().equals(JQGridContants.EDIT_OPER_ADD)) {
            loginLoginInfoService.add(loginLogInfo);
        } else if (loginLogInfo.getOper().equals(JQGridContants.EDIT_OPER_UPDATE)) {
            loginLogInfo.setLoginId(loginLogInfo.getId());
            loginLoginInfoService.update(loginLogInfo);
        } else if (loginLogInfo.getOper().equals(JQGridContants.EDIT_OPER_DEL)) {
            JQGridUtils.delete("delete from login_log_info where login_id ", loginLogInfo.getId());
        }
        JQGridUtils.warnUserMessage(warnMessage, response);
    }
}
